Component({
    properties: {
        min: {
            type: Number,
            value: 0
        },
        max: {
            type: Number,
            value: 100
        },
        int: {
            type: Boolean,
            value: !0
        },
        step: {
            type: Number,
            value: 1
        },
        single: {
            type: Number,
            value: 8
        },
        fiexNum: {
            type: Number,
            value: 0
        },
        h: {
            type: Number,
            value: 120
        },
        active: {
            type: null,
            value: "0",
            observer: function(e, t, s) {
                console.log(t);
                var i = this.data.rul;
                i.active = e, console.log(e, "new");
                var a = this.assignValue(this, i);
                this.setData({
                    centerNum: a,
                    rul: i
                });
            }
        },
        styles: {
            type: Object,
            value: {
                line: "#ffffff",
                bginner: "#ffffff",
                bgoutside: "#ffffff",
                lineSelect: "#52b8f5",
                font: "#404040"
            }
        }
    },
    data: {
        imageWidth: "",
        fiexNum: 0,
        bgoutside: "#18ff06",
        lineSelect: "#52b8f5",
        scaleId: "",
        rul: {},
        assingOldVal: -1,
        system: ""
    },
    ready: function() {
        var e = this;
        this._init(), wx.getSystemInfo({
            success: function(t) {
                var s = t.system.split(" ")[0];
                console.log(s), e.setData({
                    system: s
                });
            }
        });
    },
    methods: {
        draw: function(e, t, s) {
            var i = this, a = s.self, n = s.rul, l = wx.createCanvasContext("canvas", a);
            l.save(), l.setFillStyle(n.styles.bginner), l.fillRect(0, 0, t, 80), l.restore(), 
            l.beginPath(), l.setLineWidth(1), l.setStrokeStyle(n.styles.line), l.moveTo(n.FIXED_NUM / 2, 0), 
            l.lineTo(t - n.FIXED_NUM / 2, 0), l.stroke(), console.log("每一个的角度", n.single);
            for (var o = 0; o < n.unitNum + 1; o++) "iOS" == this.data.system ? (o % 10 == 0 && (l.setFontSize(26), 
            l.setFillStyle(n.styles.font), l.setTextAlign("center"), l.fillText(o / 10, o * n.single * n.step + 9, 65)), 
            o % 10 == 0 ? (l.beginPath(), l.setLineWidth(2), l.setStrokeStyle(n.styles.line), 
            l.moveTo(o * n.spa + 9, -2), l.lineTo(o * n.spa + 9, 40), l.stroke()) : o % 5 == 0 ? (l.beginPath(), 
            l.setLineWidth(2), l.setStrokeStyle(n.styles.line), l.moveTo(o * n.spa + 9, -2), 
            l.lineTo(o * n.spa + 9, 30), l.stroke()) : (l.beginPath(), l.setLineWidth(1), l.setStrokeStyle(n.styles.line), 
            l.moveTo(o * n.spa + 9, -2), l.lineTo(o * n.spa + 9, 20), l.stroke())) : (o % 10 == 0 && (l.setFontSize(18), 
            l.setFillStyle(n.styles.font), l.setTextAlign("center"), l.fillText(o / 10, o * n.single * n.step, 65)), 
            o % 10 == 0 ? (l.beginPath(), l.setLineWidth(2), l.setStrokeStyle(n.styles.line), 
            l.moveTo(o * n.spa, -2), l.lineTo(o * n.spa, 40), l.stroke()) : o % 5 == 0 ? (l.beginPath(), 
            l.setLineWidth(2), l.setStrokeStyle(n.styles.line), l.moveTo(o * n.spa, -2), l.lineTo(o * n.spa, 30), 
            l.stroke()) : (l.beginPath(), l.setLineWidth(1), l.setStrokeStyle(n.styles.line), 
            l.moveTo(o * n.spa, -2), l.lineTo(o * n.spa, 20), l.stroke()));
            l.draw(!0, setTimeout(function() {
                wx.canvasToTempFilePath({
                    x: 0,
                    y: 0,
                    width: t,
                    height: 80,
                    canvasId: "canvas",
                    success: function(e) {
                        n.total = n.total / 80 * n.h, n.FIXED_NUM = n.FIXED_NUM / 80 * n.h;
                        var t = i.assignValue(i, n);
                        a.setData({
                            ruler: e.tempFilePath,
                            centerNum: t,
                            width: n.total,
                            h: n.h,
                            fiexNum: n.FIXED_NUM,
                            round: a.data.int ? n.minNum : n.minNum.toFixed(1),
                            bgoutside: n.styles.bgoutside,
                            lineSelect: n.styles.lineSelect
                        }), console.log(i.data.ruler), a.triggerEvent("value", {
                            value: a.data.round
                        });
                    },
                    fail: function(e) {
                        console.log(e);
                    }
                }, i);
            }, 500));
        },
        bindscroll: function(e) {
            var t, s = this, i = this.data.rul, a = e.detail.scrollLeft;
            t = this.data.int ? parseInt(i.total - i.FIXED_NUM) / i.num * i.step : parseFloat(i.total - i.FIXED_NUM) / i.num / (i.single / i.step);
            var n = Math.round(a / t), l = Math.round(n * t);
            n = this.data.int ? n * i.step + i.minNum : (n * i.step / 10 + i.minNum).toFixed(1), 
            this.data.assingOldVal !== n && (this.setData({
                round: n,
                assingOldVal: n
            }), this.triggerEvent("value", {
                value: n
            }), clearTimeout(i.Timer), i.Timer = setTimeout(function() {
                s.setData({
                    centerNum: l,
                    round: n,
                    active: n,
                    assingOldVal: n
                }), s.triggerEvent("value", {
                    value: n
                });
            }, 200));
        },
        _init: function() {
            var e = this, t = {
                spa: "",
                unitNum: "",
                minNum: this.data.min,
                maxNum: this.data.max,
                num: this.data.max - this.data.min,
                FIXED_NUM: this.data.fiexNum,
                single: this.data.single,
                step: this.data.step,
                h: this.data.h,
                active: "",
                styles: this.data.styles
            };
            this._getErro(t), this.createSelectorQuery().in(this).select("#scale-wrapper").boundingClientRect(function(e) {
                e.top;
            }).exec(function(s) {
                t.windowWidth = s[0].height, e.data.int ? t.unitNum = t.num / t.step : t.unitNum = t.num * (t.single / t.step), 
                t.spa = t.single * t.step, t.total = t.spa * t.unitNum + t.FIXED_NUM, e.setData({
                    windowWidth: s[0].width,
                    width: t.total,
                    fiexNum: t.FIXED_NUM,
                    rul: t
                }), e.draw(t.num, t.total, {
                    self: e,
                    rul: t
                });
            });
        },
        _getErro: function(e) {
            e.minNum >= e.maxNum && (e.minNum = 0, e.maxNum = 100, e.num = e.maxNum - e.minNum), 
            1 !== e.step && 2 !== e.step && 5 !== e.step && (e.step = 1), e.FIXED_NUM < 60 && (e.FIXED_NUM || (e.FIXED_NUM = 60), 
            e.FIXED_NUM < 0 && (e.FIXED_NUM = 0)), e.single < 10 && (e.single || (e.single = 10)), 
            e.h < 50 && (console.warn("格子单位小于50 ，可能影响显示效果，请检查 h"), e.h || (e.h = 80), e.h < 20 && (console.error("高度最小为20  ，请检查 h"), 
            e.h = 20)), "min" === this.data.active ? e.active = e.minNum : "max" === this.data.active ? e.active = e.maxNum : "center" === this.data.active ? e.active = (e.maxNum + e.minNum) / 2 : e.active = this.data.active, 
            "min" !== this.data.active && "max" !== this.data.active && "center" !== this.data.active && ((e.active < e.minNum || e.active > e.maxNum) && console.error("您输入的数值（active）超入范围，请检查 active"), 
            e.active % e.step != 0 && e.int && console.warn("您输入的数值（active）不是合法数值，请检查，所以导致结果可能有错误"), 
            10 * e.active % e.step == 0 || e.int || console.warn("您输入的数值（active）不是合法数值，请检查，所以导致结果可能有错误")), 
            e.styles ? (e.styles.line || (e.styles.line = "#ffffff"), e.styles.lineSelect || (e.styles.lineSelect = "#52b8f5"), 
            e.styles.bginner || (e.styles.bginner = "#ffffff"), e.styles.bgoutside || (e.styles.bgoutside = "#ffffff"), 
            e.styles.font || (e.styles.font = "#404040")) : (e.styles = {}, e.styles.line || (e.styles.line = "#ffffff"), 
            e.styles.lineSelect || (e.styles.lineSelect = "#52b8f5"), e.styles.bginner || (e.styles.bginner = "#ffffff"), 
            e.styles.bgoutside || (e.styles.bgoutside = "#ffffff"), e.styles.font || (e.styles.font = "#404040"));
        },
        assignValue: function(e, t) {
            return e.data.int ? (t.active - t.minNum) / t.step * parseInt(t.total - t.FIXED_NUM) / t.num * t.step : 10 * (t.active - t.minNum) / t.step * parseFloat(t.total - t.FIXED_NUM) / t.num / (t.single / t.step);
        }
    }
});